package com.it.jasypt.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.it.jasypt.config.SensitiveData;
import com.it.jasypt.config.SensitiveDataCommonSerializer;
import com.it.jasypt.config.SensitiveDataIdCardByRoleSerializer;
import com.it.jasypt.config.SensitiveDataIdCardSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class UserDTO extends UserEntity {

    private Long id;

    @JsonIgnore
    private String password;

    @JsonSerialize(using = SensitiveDataCommonSerializer.class)
    private String idCard;

    @JsonSerialize(using = SensitiveDataCommonSerializer.class)
    private String phone;

    @JsonSerialize(using = SensitiveDataCommonSerializer.class)
    private String email;

    @JsonSerialize(using = SensitiveDataIdCardSerializer.class) // 指定IdCard的方法
    private String idCard2;

    @JsonSerialize(using = SensitiveDataIdCardByRoleSerializer.class) // 动态脱敏
    private String idCard3;

    // 指定参数动态脱敏
    @SensitiveData(hasAnyRole = {"ADMIN"}, maskPattern = "^(\\d{3})\\d{11}(\\d{4})$", maskReplacement = "$1***********$2")
    private String idCard4;
}
